//
//  YZEShebaoTableViewController.m
//  yilutongxing
//
//  Created by T&J on 2017/5/22.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "YZEMedicalTableViewController.h"
#import "YZEMyinfoTableViewController.h"
#import "IQActionSheetPickerView.h"
#import "URLManager.h"

@interface YZEMedicalTableViewController ()

@property (copy, nonatomic) NSString *medical_alias;
@property (copy, nonatomic) NSMutableArray *medicalArr;

@end

#define REQ_ID_SaveMedical 100003

@implementation YZEMedicalTableViewController
-(void)setCell_shebao:(UITableViewCell *)cell_shebao{
    _cell_shebao = cell_shebao;
}

-(void)setMedical_type:(NSString *)medical_type{
    _medical_type = medical_type;
}

-(void)setLastView:(YZEMyinfoTableViewController *)lastView{
    _lastView = lastView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title = @"我的社保";
    //右侧保存按钮
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStyleDone target:self action:@selector(onSaveClick:)];
    self.navigationItem.rightBarButtonItem = btn;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    if ([_medical_type compare:@"TOWN"]==0) {
        self.medical_alias = @"城镇居民医保";
    }
    else if([_medical_type compare:@"COUNTRYSIDE"]==0){
        self.medical_alias = @"乡村居民医保";
    }
    self.cell_shebao.detailTextLabel.text = _medical_alias;
    
    //医保类型
    self.medicalArr = [NSMutableArray arrayWithObjects:@"城镇居民医保",@"乡村居民医保", nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"选择社保类型" delegate:self];
    picker.titleFont = [UIFont systemFontOfSize:12];
    picker.titleColor = [UIColor redColor];
    [picker setTag:1];
    [picker setTitlesForComponents:@[self.medicalArr]];
    [picker show];
}

//列表选择响应
-(void)actionSheetPickerView:(IQActionSheetPickerView *)pickerView didSelectTitles:(NSArray *)titles{
    if (pickerView.tag==1) {
        NSString *strType = [titles componentsJoinedByString:@""];
        if ([strType compare:self.medicalArr[0]]==0) {
            self.medical_alias = @"TOWN";
        }
        else if([strType compare:self.medicalArr[1]]==0){
            self.medical_alias = @"COUNTRYSIDE";
        }
        debugLog(@"medical:%@", self.medical_alias);
        self.cell_shebao.detailTextLabel.text = strType;
    }
}

//保存点击响应
-(void)onSaveClick:(UIButton *)sender{
    NSString *paramURL = [[URL_MedicalType stringByAppendingString:@"/"] stringByAppendingString:self.medical_alias];
    [[YZENetwork sharedInstace] postRequestWithUrl:paramURL parameters:nil delegate:self requestTag:REQ_ID_SaveMedical successBlock:^(id responseObject) {
        [self.lastView setMedical:self.medical_alias];
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
